package com.weikuang.fareast.activityNew;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.trello.rxlifecycle2.android.ActivityEvent;
import com.weikuang.fareast.R;
import com.weikuang.fareast.activity.BaseActivity;
import com.weikuang.fareast.adapter.NumberAdapter;
import com.weikuang.fareast.adapter.OrderNoAdapter;
import com.weikuang.fareast.bean.BranchCodeList;
import com.weikuang.fareast.bean.ChangOrderBean;
import com.weikuang.fareast.bean.OrderNoInfoBean;
import com.weikuang.fareast.network.KillerApi;
import com.weikuang.fareast.network.MainApi;
import com.weikuang.fareast.network.MyObserve;
import com.weikuang.fareast.utils.UserHelper;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.dlc.commonlibrary.ui.widget.TitleBar;
import cn.dlc.commonlibrary.utils.ToastUtil;
import cn.dlc.commonlibrary.utils.rv_tool.RecyclerViewUtil;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * 订好具体信息
 */

public class OrderNoActivity extends BaseActivity {
    @BindView(R.id.mTitleBar)
    TitleBar mTitleBar;

    @BindView(R.id.recycler)
    RecyclerView mRecyclerView;


    private OrderNoAdapter mOrderNoAdapter;
    private ChangOrderBean.DataBean changorderNo ;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_orderno;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        mTitleBar.leftExit(this);
        OrderNoInfoBean orderNoInfoBean = (OrderNoInfoBean) getIntent().getSerializableExtra("datas");

        InitRecyclerView();
       // getUser();
        getorder_No(orderNoInfoBean);

    }

    private void InitRecyclerView() {
        mOrderNoAdapter = new OrderNoAdapter();
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        mRecyclerView.setLayoutManager(linearLayoutManager);
        RecyclerViewUtil.setDefaultDivider(mRecyclerView, linearLayoutManager);
        mRecyclerView.setAdapter(mOrderNoAdapter);

        mOrderNoAdapter.setOnItemClickListener(new OrderNoAdapter.OnRecyclerViewItemClickListener() {
            @Override
            public void onItemClick(View view, ChangOrderBean.DataBean data, int position) {
                changorderNo = data;
                Intent i = new Intent();
                i.putExtra("data",changorderNo);
                setResult(5, i);
                finish();
            }
        });
    }

    /**
     * 获取订单的订单编号
     */
    private void getorder_No(OrderNoInfoBean orderNoInfoBean) {



        showWaitingDialog("请等待",true);
        MainApi.getInstance().getApi( KillerApi.class)
                .getOrderList(UserHelper.get().getUserid(),orderNoInfoBean.branchId,UserHelper.get().getUserid(),orderNoInfoBean.customerId,orderNoInfoBean.startTime,
                        orderNoInfoBean.endTime,orderNoInfoBean.state)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .compose(bindUntilEvent(ActivityEvent.DESTROY))
                .subscribe(new MyObserve<ChangOrderBean>() {
                    @Override
                    public void onNetError(Throwable e) {
                        showOneToast(getString(R.string.order_34));
                    }

                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(ChangOrderBean changListBean) {
                        dismissWaitingDialog();
                        mOrderNoAdapter.setNewData(changListBean.getData());

                    }
                });
    }


}
